package cate.game.role.pvp.throne.msg;

import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBTB;
import cate.game.pvp.throne.data.trial.TBTrialRank;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@ClientMsg(title = "选拔赛排行榜 の 请求")
public class TBTrialRankReq implements MsgInput {

    @NoteField("分组")
    public int group;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        List<TBTrialRank> rankList = game.pvp.throne.data.getTrialRank(group);
        TBTrialRankResp resp = new TBTrialRankResp();
        resp.group = group;
        resp.rankList = rankList;
        for (int i = 0; i < rankList.size(); i++) {
            TBTrialRank tbTrialRank = rankList.get(i);
            if (StringUtils.equals(tbTrialRank.owner.uid, cc.getRole().getUid())) {
                resp.my = tbTrialRank;
                resp.myRank = i + 1;
                break;
            }
        }
        resp.sendNow(cc.getRole());
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBTB.TRIAL_RANK_REQ;
    }
}
